package com.xwh.article.controller;

import com.xwh.article.client.SystemService;
import com.xwh.article.entity.SoftwareVersionDownload;
import com.xwh.article.service.SoftwareDownloadService;
import com.xwh.core.controller.BaseController;
import com.xwh.core.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xwh
 **/

@RequiredArgsConstructor
@RestController
@RequestMapping("/softwareDownload")
@Tag(name = "应用:软件下载管理")
@Slf4j
public class SoftwareDownloadController extends BaseController {

    final SoftwareDownloadService softwareDownloadService;
    final SystemService systemService;

    @Operation(summary = "获取软件下载列表")
    @GetMapping("/list/{softwareVersionId}")
    public Result list(@PathVariable("softwareVersionId") String softwareVersionId) {
        List<SoftwareVersionDownload> list = softwareDownloadService.listBySoftwareVersion(softwareVersionId);
        return success().add(list);
    }

    @Operation(summary = "获取软件下载类型列表")
    @GetMapping("/softwareType")
    public Result softwareType() {
        return systemService.get("software_download_type").block();
    }

    @Operation(summary = "新增软件下载")
    @PostMapping("/{versionId}")
    public Result add(@RequestBody List<SoftwareVersionDownload> list, @PathVariable String versionId) {
        softwareDownloadService.add(list, versionId);
        return success();
    }

    @Operation(summary = "删除软件下载")
    @DeleteMapping("/{softwareVersionDownloadId}")
    public Result delete(@PathVariable("softwareVersionDownloadId") String softwareVersionDownloadId) {
        softwareDownloadService.removeById(softwareVersionDownloadId);
        return success();
    }

    @Operation(summary = "修改软件下载")
    @PutMapping()
    public Result update(@RequestBody SoftwareVersionDownload softwareVersionDownload) {
        softwareDownloadService.updateById(softwareVersionDownload);
        return success();
    }

}
